home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / TimGA 1.2.1 / .cp / CTerminationDialog.cp < prev    next >
Encoding:
Text File  |  1997-07-16  |  8.0 KB  |  269 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CTerminationDialog.cp    ©1995-97 Timo Eloranta        All rights reserved.
  3. // ===========================================================================
  4.  
  5. #include "CTerminationDialog.h"
  6. #include "GraphGA_PaneIDs.h"
  7.  
  8. #include <PP_Messages.h>
  9. #include <UReanimator.h>
  10.  
  11. #include <LGAEditField.h>
  12. #include <LGAPushButton.h>
  13. #include <LGACheckbox.h>
  14.  
  15.  
  16. // ---------------------------------------------------------------------------
  17. //        • CTerminationDialog
  18. //
  19. //          Called by:    URegistrar::CreateObject
  20. // ---------------------------------------------------------------------------
  21.  
  22. CTerminationDialog::CTerminationDialog( LStream *inStream )
  23.     : LGADialogBox( inStream )
  24. {
  25. }
  26.  
  27. // ---------------------------------------------------------------------------
  28. //        • InitDialog
  29. //
  30. //          Called by:    CGraphGAApp::ObeyCommand
  31. // ---------------------------------------------------------------------------
  32.  
  33. void
  34. CTerminationDialog::InitDialog()
  35. {
  36.     mFactoryButton    = (LGAPushButton *) this -> FindPaneByID( but_FactorySettings );
  37.         
  38.     mMaxGenBox        = (LGACheckbox *) this -> FindPaneByID( cbox_MaxGen );
  39.     mMaxGenNoBox    = (LGACheckbox *) this -> FindPaneByID( cbox_MaxGenNo );
  40.     mMaxTimeBox        = (LGACheckbox *) this -> FindPaneByID( cbox_MaxTime );
  41.     mMaxTimeNoBox    = (LGACheckbox *) this -> FindPaneByID( cbox_MaxTimeNo );
  42.     mCrossingsBox    = (LGACheckbox *) this -> FindPaneByID( cbox_NoCrossings );
  43.  
  44.     UReanimator::LinkListenerToControls( this, this, WIND_Terminate );
  45.  
  46.     mMaxGenEdit        = (LGAEditField *) this -> FindPaneByID( edit_MaxGen );
  47.     mMaxGenNoEdit    = (LGAEditField *) this -> FindPaneByID( edit_MaxGenNo );
  48.     mMaxTimeEdit    = (LGAEditField *) this -> FindPaneByID( edit_MaxTime );
  49.     mMaxTimeNoEdit    = (LGAEditField *) this -> FindPaneByID( edit_MaxTimeNo );
  50. }
  51.  
  52. // ---------------------------------------------------------------------------
  53. //        • SetValues
  54. //
  55. //          Called by:    CGraphGAApp::ObeyCommand
  56. // ---------------------------------------------------------------------------
  57.  
  58. void
  59. CTerminationDialog::SetValues( STermination &inTermination )
  60. {
  61.     mMaxGenBox ->        SetValue( inTermination.stopMaxGenTotal );
  62.     mMaxGenNoBox ->        SetValue( inTermination.stopMaxGenNoChange );
  63.     mMaxTimeBox ->        SetValue( inTermination.stopMaxTimeTotal );
  64.     mMaxTimeNoBox ->    SetValue( inTermination.stopMaxTimeNoChange );
  65.     mCrossingsBox ->    SetValue( inTermination.stopNoCrossings );
  66.  
  67.     mMaxGenEdit ->        SetValue( inTermination.maxGenTotal );
  68.     mMaxGenNoEdit ->    SetValue( inTermination.maxGenNoChange );
  69.     mMaxTimeEdit ->        SetValue( inTermination.maxTimeTotal / 60L );
  70.     mMaxTimeNoEdit ->    SetValue( inTermination.maxTimeNoChange / 60L );
  71.  
  72.     if ( ! inTermination.stopMaxGenTotal ) {
  73.         mMaxGenEdit -> Disable();
  74.         mMaxGenEdit -> Deactivate();
  75.     }
  76.     if ( ! inTermination.stopMaxGenNoChange ) {
  77.         mMaxGenNoEdit -> Disable();
  78.         mMaxGenNoEdit -> Deactivate();
  79.     }
  80.     if ( ! inTermination.stopMaxTimeTotal ) {
  81.         mMaxTimeEdit -> Disable();
  82.         mMaxTimeEdit -> Deactivate();
  83.     }
  84.     if ( ! inTermination.stopMaxTimeNoChange ) {
  85.         mMaxTimeNoEdit -> Disable();
  86.         mMaxTimeNoEdit -> Deactivate();
  87.     }
  88.  
  89.     if ( inTermination.stopMaxGenTotal ) {
  90.         mMaxGenEdit -> SelectAll();
  91.         SetLatentSub( mMaxGenEdit );
  92.     }
  93.     else if ( inTermination.stopMaxGenNoChange ) {
  94.             mMaxGenNoEdit -> SelectAll();
  95.             SetLatentSub( mMaxGenNoEdit );
  96.         }
  97.             else if ( inTermination.stopMaxTimeTotal ) {
  98.                 mMaxTimeEdit -> SelectAll();
  99.                 SetLatentSub( mMaxTimeEdit );
  100.             }
  101.                 else if ( inTermination.stopMaxTimeNoChange ) {
  102.                     mMaxTimeNoEdit -> SelectAll();
  103.                     SetLatentSub( mMaxTimeNoEdit );
  104.                 }
  105.                 
  106.     AdjustFactoryButton();
  107. }
  108.  
  109. // ---------------------------------------------------------------------------
  110. //        • SetDefaultValues    (PRIVATE)
  111. //
  112. //          Called by:    CTerminationDialog::ListenToMessage
  113. // ---------------------------------------------------------------------------
  114.  
  115. void
  116. CTerminationDialog::SetDefaultValues( )
  117. {
  118.     mMaxGenEdit ->        SetValue( DEFAULT_MAX_GEN_TOTAL );
  119.     mMaxGenNoEdit ->    SetValue( DEFAULT_MAX_GEN_NO_CHANGE );
  120.     mMaxTimeEdit ->        SetValue( DEFAULT_MAX_TIME_TOTAL / 60L );
  121.     mMaxTimeNoEdit ->    SetValue( DEFAULT_MAX_TIME_NO_CHANGE / 60L );
  122.  
  123.     mMaxGenBox ->        SetValue( Button_Off );
  124.     mMaxGenNoBox ->        SetValue( Button_Off );
  125.     mMaxTimeBox ->        SetValue( Button_Off );
  126.     mMaxTimeNoBox ->    SetValue( Button_Off );
  127.     mCrossingsBox ->    SetValue( Button_Off );
  128. }
  129.  
  130. // ---------------------------------------------------------------------------
  131. //        • GetValues
  132. //
  133. //          Called by:    CGraphGAApp::SetTerFromDialog
  134. // ---------------------------------------------------------------------------
  135.  
  136. void
  137. CTerminationDialog::GetValues( STermination &outTermination )
  138. {
  139.     outTermination.stopMaxGenTotal        = mMaxGenBox ->        GetValue();
  140.     outTermination.stopMaxGenNoChange    = mMaxGenNoBox ->    GetValue();
  141.     outTermination.stopMaxTimeTotal        = mMaxTimeBox ->    GetValue();
  142.     outTermination.stopMaxTimeNoChange    = mMaxTimeNoBox ->    GetValue();
  143.     outTermination.stopNoCrossings        = mCrossingsBox ->    GetValue();
  144.  
  145.     outTermination.maxGenTotal        = mMaxGenEdit ->     GetValue();
  146.     outTermination.maxGenNoChange    = mMaxGenNoEdit ->     GetValue();
  147.     outTermination.maxTimeTotal        = (mMaxTimeEdit ->     GetValue()) * 60L;
  148.     outTermination.maxTimeNoChange    = (mMaxTimeNoEdit -> GetValue()) * 60L;
  149. }
  150.  
  151. // ---------------------------------------------------------------------------
  152. //        • ListenToMessage
  153. //
  154. //          Called by:    LBroadcaster::BroadcastMessage
  155. // ---------------------------------------------------------------------------
  156.  
  157. void
  158. CTerminationDialog::ListenToMessage(
  159.     MessageT    inMessage, 
  160.     void        *ioParam )
  161. {
  162.     switch ( inMessage ) {
  163.  
  164.         case msg_MaxGen:
  165.             if ( mMaxGenBox -> GetValue() ) {
  166.                 SwitchTarget( mMaxGenEdit );
  167.                 mMaxGenEdit -> Enable();
  168.                 mMaxGenEdit -> Activate();
  169.                 mMaxGenEdit -> SelectAll();
  170.             } else {
  171.                 mMaxGenEdit -> Disable();
  172.                 mMaxGenEdit -> Deactivate();
  173.             }
  174.             AdjustFactoryButton();
  175.             break;
  176.  
  177.         case msg_MaxGenNo:
  178.             if ( mMaxGenNoBox -> GetValue() ) {
  179.                 SwitchTarget( mMaxGenNoEdit );
  180.                 mMaxGenNoEdit -> Enable();
  181.                 mMaxGenNoEdit -> Activate();
  182.                 mMaxGenNoEdit -> SelectAll();
  183.             } else {
  184.                 mMaxGenNoEdit -> Disable();
  185.                 mMaxGenNoEdit -> Deactivate();
  186.             }
  187.             AdjustFactoryButton();
  188.             break;
  189.  
  190.         case msg_MaxTime:
  191.             if ( mMaxTimeBox -> GetValue() ) {
  192.                 SwitchTarget( mMaxTimeEdit );
  193.                 mMaxTimeEdit -> Enable();
  194.                 mMaxTimeEdit -> Activate();
  195.                 mMaxTimeEdit -> SelectAll();
  196.             } else {
  197.                 mMaxTimeEdit -> Disable();
  198.                 mMaxTimeEdit -> Deactivate();
  199.             }
  200.             AdjustFactoryButton();
  201.             break;
  202.  
  203.         case msg_MaxTimeNo:
  204.             if ( mMaxTimeNoBox -> GetValue() ) {
  205.                 SwitchTarget( mMaxTimeNoEdit );
  206.                 mMaxTimeNoEdit -> Enable();
  207.                 mMaxTimeNoEdit -> Activate();
  208.                 mMaxTimeNoEdit -> SelectAll();
  209.             } else {
  210.                 mMaxTimeNoEdit -> Disable();
  211.                 mMaxTimeNoEdit -> Deactivate();
  212.             }
  213.             AdjustFactoryButton();
  214.             break;
  215.  
  216.         case msg_NoCrossings:
  217.             AdjustFactoryButton();
  218.             break;
  219.         
  220.         case msg_FactorySettings:
  221.             SetDefaultValues( );
  222.             break;
  223.             
  224.         default:    
  225.             LGADialogBox::ListenToMessage( inMessage, ioParam );
  226.             break;
  227.     }
  228. }
  229.  
  230. // ---------------------------------------------------------------------------
  231. //        • AdjustFactoryButton    (PRIVATE)
  232. //
  233. //          Called by:    CTerminationDialog::SetValues
  234. //                        CTerminationDialog::ListenToMessage
  235. // ---------------------------------------------------------------------------
  236.  
  237. void
  238. CTerminationDialog::AdjustFactoryButton( )
  239. {
  240.     if ( ! ( mMaxGenBox -> GetValue() || mMaxGenNoBox -> GetValue() ||
  241.              mMaxTimeBox -> GetValue() || mMaxTimeNoBox -> GetValue() ||
  242.              mCrossingsBox -> GetValue() ) )
  243.             mFactoryButton -> Disable();
  244.     else
  245.         if ( ! mFactoryButton -> IsEnabled() ) 
  246.              mFactoryButton -> Enable();
  247. }
  248.  
  249. // ---------------------------------------------------------------------------
  250. //        • FindCommandStatus
  251. //
  252. //          Called by:    LCommander::ProcessCommandStatus
  253. // ---------------------------------------------------------------------------
  254. //    Disable all menu items except for the one which opens the About box.
  255.  
  256. void
  257. CTerminationDialog::FindCommandStatus(
  258.     CommandT    inCommand,
  259.     Boolean        &outEnabled,
  260.     Boolean&    /* outUsesMark */,
  261.     Char16&        /* outMark */,
  262.     Str255        /* outName */)
  263. {
  264.     outEnabled = false;
  265.     if (inCommand == cmd_About) {
  266.         outEnabled = true;
  267.     }
  268. }
  269.